$(function() {
    $(".loadingMarsk").css({
        "width":window.screen.availWidth,
        "height":window.screen.availHeight,
    });
    //设置跳转
    $(".userData").on("click",".setting",function(){
        location.href = "./setting.html";
    });
    //获取token
    var token = localStorage.token;
    if(!token) {
        location.href = "../loginAndReg/login.html";
        return false;
    };
    new FastClick(document.body);
    //获取头像用户名
    var headPic = localStorage.userHeadPic;
    if(headPic==="undefined") headPic = "../../static/img/head_l@3x.png";
    var nickname = localStorage.nickname;
    $.ajax({
        type: "get",
        url: domain.test + "/getme",
        // url: domain.online + "/member/index",
        //设置请求头
        beforeSend:function(xhr) {    
            $(".loadingMarsk").css("display","block");            
            xhr.setRequestHeader("token",token);
        },
        success: function (response) {
            if(response.data.rtnCode===200) {
            // if(response.rtnCode===200) {
                var userData = response.data.data;
                // var userData = response.data;
                //设置头像用户名
                userData.headPic = headPic;
                userData.nickname = nickname;
                $(".userData").html(template("userData",{userData:userData}));
                $(".loadingMarsk").css("display","none");
            }
            if(response.data.rtnCode===401) {
            // if(response.rtnCode===401) {
                var outTimeCode = response.data.rtnCode;
                // var outTimeCode = response.rtnCode;
                location.href = "../../index.html?outTimeCode=" + outTimeCode;
            }
        }
    });
    //收藏跳转
    $(".userData").on("click",".cleBtn",function() {
        location.href = "./collection.html";
    });
    //地址跳转
    $(".userData").on("click",".addBtn",function() {
        location.href = "./address.html";
    });
    //购物车跳转
    $(".userData").on("click",".carBtn",function() {
        location.href = "./shoppingCar.html";
    });
    //订单跳转
    $(".userData").on("click",".orderBtn",function() {
        location.href = "./orders.html";
    });
    //消息跳转
    $(".userData").on("click",".msg",function() {
        location.href = "./msgCenter.html";
    });
    //个人资料跳转
    $(".userData").on("click",".userHeader",function() {
        location.href = "./myMsg.html";
    });
});